const router = require('koa-router')();
let querystring = require("querystring");

router.get('/first', async (ctx) => {
  const url = 'https://open.weixin.qq.com/connect/oauth2/authorize';
  const info = {
    appid: 'wx43a850f87498127d',
    // redirect_uri: 'http://wx.10086.cn/website/automatic/servicePwd/index.html',
    redirect_uri: ctx.request.originalUrl,
    response_type: 'code',
    scope: 'snsapi_base',
    state: ''
  };
  console.log('info', info);
  let redirectUrl = `${url}?${querystring.stringify(info)}#wechat_redirect`;
  console.log('redirectUrl', redirectUrl);
  ctx.redirect(redirectUrl);
})

router.get('/second', async (ctx) => {
  ctx.body = {returncode: 201}
})

router.get('/third', async (ctx) => {
  ctx.body = {returncode: 201}
})

module.exports = router;